﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Top.Api;
using Top.Api.Request;
using Top.Api.Response;

namespace thousandClear.Util.SMS
{
    public class SMSClient
    {
        public bool SendRegSMS(string mobile, string code, out string errCode, out string errMsg)
        {
            errCode = string.Empty;
            errMsg = string.Empty;

            ITopClient client = new DefaultTopClient("http://gw.api.taobao.com/router/rest", "23272676", "1a4ffe6bc25687f636d6b5e6c5a4e186");
            AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
            req.Extend = "123456";
            req.SmsType = "normal";
            req.SmsFreeSignName = "注册验证";
            req.SmsParam = "{\"code\":\""+code+"\", \"product\":\"一箱茶艺\"}";
            req.RecNum = mobile;
            req.SmsTemplateCode = "SMS_2555592";
            AlibabaAliqinFcSmsNumSendResponse resp = client.Execute(req);

            if(resp.Result == null)
            {
                errCode = resp.ErrCode;
                errMsg = resp.ErrMsg;
                return false;
            }

            if(resp.Result.Success)
            {
                return true;
            }
            else
            {
                errCode = resp.Result.Model;
                errMsg = resp.Result.Msg;

                return false;
            }
        }
    }
}
